<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>

<head>
    <base href="${pageContext.request.contextPath}/"/>
    <title>襄阳蓝芯智能化办公系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="view/bootstrap-3.3.5/css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="view/bootstrapvalidator/css/bootstrapValidator.css"/>
    <script charset="utf-8" src="view/jquery/jquery-1.10.2.min.js"></script>
    <script charset="utf-8" src="view/bootstrap-3.3.5/js/bootstrap.js"></script>
    <script charset="utf-8" src="view/bootstrapvalidator/js/bootstrapValidator.js"></script>
</head>
<body>


<div class="panel panel-primary">
    <div class="panel-heading">
        <h4 class="panel-title">编辑部门信息</h4>
    </div>

    <div class="panel-body">
        <form action="dept/AddDept" id="myform" method="post"
              class="form-horizontal" role="form">
            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="deptName" class="col-md-4 control-label">部门名称</label>
                    <div class="col-md-8">
                        <input type="hidden" id="oid" name="oid" value="${dept.oid }">
                        <input type="text" id="deptName" name="deptName"
                               class="form-control" placeholder="请输入部门名称"
                               value="${dept.deptName }">
                    </div>
                </div>

                <div class="form-group col-md-6">
                    <label for="phone" class="col-md-4 control-label">部门电话</label>
                    <div class="col-md-8">
                        <input type="text" id="phone" name="phone" class="form-control"
                               placeholder="请输入部门电话" value="${dept.phone }">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="parentoid" class="col-md-4 control-label">上级部门</label>
                    <div class="col-md-8">
                        <select name="parentoid" class="form-control" id="parentoid">
                            <option value="">--请选择--</option>
                            <c:forEach items="${listDeptNames }" var="d">
                                <option value="${d.oid }"
                                    ${d.oid==dept.parentoid?"selected":"" }>${d.deptName }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="fax" class="col-md-4 control-label">部门传真</label>
                    <div class="col-md-8">
                        <input type="text" id="fax" name="fax" class="form-control"
                               placeholder="请输入部门传真" value="${dept.fax }">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="manager" class="col-md-4 control-label">部门经理</label>
                    <div class="col-md-8">
                        <input type="hidden" id="manager" name="manager"
                               value="${dept.manager }">

                        <div class="input-group">
                            <input type="text" id="managername" name="managername"
                                   readonly="readonly" class="form-control" placeholder="请选择部门经理"
                                   value="${dept.emp.empName }"> <span
                                class="input-group-btn">
									<button class="btn btn-info" type="button"
                                            data-toggle="modal" data-target="#selectempModal">请选择</button>
								</span>
                        </div>
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="email" class="col-md-4 control-label">部门邮箱</label>
                    <div class="col-md-8">
                        <input type="text" id="email" name="email" class="form-control"
                               placeholder="请输入部门邮箱" value="${dept.email }">
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="zipcode" class="col-md-4 control-label">部门邮编</label>
                    <div class="col-md-8">
                        <input type="text" id="zipcode" name="zipcode"
                               class="form-control" placeholder="请输入部门邮编"
                               value="${dept.zipcode }">
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="address" class="col-md-4 control-label">部门地址</label>
                    <div class="col-md-8">
                        <input type="text" id="address" name="address"
                               class="form-control" placeholder="请输入部门地址"
                               value="${dept.address }">
                    </div>
                </div>
            </div>


            <div class="col-md-12">
                <div class="form-group col-md-6">
                    <label for="description" class="col-md-4 control-label">部门介绍</label>
                    <div class="col-md-8">
							<textarea class="form-control" id="description"
                                      name="description" rows="5" placeholder="请输入部门介绍">${dept.description }</textarea>
                    </div>
                </div>
                <div class="form-group col-md-6">
                    <label for="status" class="col-md-4 control-label">部门状态</label>
                    <div class="col-md-8">
                        <label class="radio-inline">
                            <input type="radio" name="status" ${dept.status=="q"?"checked":"" } value="q">可用
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="status" ${dept.status=="j"?"checked":"" } value="j">不可用
                        </label>
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-12">
                    <label for="jobs" class="col-md-2 control-label">部门职位&nbsp;</label>
                    <div class="col-md-9">
                        <c:forEach items="${listJobs }" var="job">
                            <label class="checkbox-inline col-xs-2">
                                <c:set var="ck" value="0"/>
                                <c:forEach items="${dept.roles }" var="djob">
                                    <c:if test="${djob.oid==job.oid }">
                                        <c:set var="ck" value="1"/>
                                    </c:if>
                                </c:forEach>
                                <input type="checkbox" name="jobsid" ${ck==1?"checked":"" }
                                       value="${job.oid }">${job.name }
                            </label>
                        </c:forEach>
                    </div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group col-md-12">
                    <div class="col-md-10  col-md-offset-2">
                        <a type="button" href="javascript:history.back()" class="btn btn-info">返回</a>
                        <button type="submit" id="editdeptbtn" class="btn btn-success">提交信息</button>
                        <button type="reset" id="resetbtn" class="btn btn-default">取消操作</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<%@include file="../modal/selectemp.jsp" %>
<script type="text/javascript">
    function setempvalue(eid, empName) {
        $("#manager").val(eid);
        $("#managername").val(empName);
    }
</script>
</body>


<script type="text/javascript">
    $(document).ready(function () {
        $("#myform").bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {/*input状态样式图片*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                deptName: {
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '部门名称不能为空'

                        },
                        stringLength: {
                            min: 2,
                            max: 20,
                            message: '部门名称长度需在2-20位'
                        },
                        remote: {
                            url: "dept/checkDeptName",
                            delay: 1000,
                            type: 'post',
                            message: '部门名称已存在!',
                            data: function (validator) {
                                return {
                                    'deptName': $("#deptName").val(),
                                    'oid': $("#oid").val(),
                                };
                            }
                        }
                    }
                },
                phone: {
                    validators: {
                        regexp: {
                            regexp: /^(^(\d{3,4}-)?\d{7,8})$|^((1[0-9][0-9]\d{8}$))$/,
                            message: '电话格式不正确'
                        }
                    }
                },
                email: {
                    validators: {
                        emailAddress: {
                            message: 'E-mail格式不正确'

                        }
                    }
                },
                fax: {
                    validators: {
                        regexp: {
                            regexp: /^(\d{3,4}-)?\d{7,8}$/,
                            message: '传真格式不正确'
                        }
                    }
                },
                zipcode: {
                    validators: {
                        regexp: {
                            regexp: /^[1-9]\d{5}$/,
                            message: '邮编格式不正确'
                        }
                    }
                },
                address: {
                    validators: {
                        stringLength: {
                            max: 200,
                            message: '地址输入过长'
                        }
                    }
                },
                description: {
                    validators: {
                        stringLength: {
                            max: 500,
                            message: '部门介绍输入过长'
                        }
                    }
                }
            },
            submitHandler: function (validator, form, submitButton) {
                validator.defaultSubmit();
            }
        });


        $("#resetbtn").click(function () {
            $("#myform").data("bootstrapValidator").resetForm();
        });
    });


</script>
</html>